package com.shxy.entity.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.shxy.util.converter.AbstractEnumConverter;
import com.shxy.util.converter.IEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.lang.Nullable;

import java.util.Random;

/**
 * 月份
 */
@Getter
@AllArgsConstructor
public enum MonthEnum implements IEnum<String> {
    JAUNARY("1", "一月"),
    FEBRUARY("1", "二月"),
    MARCH("1", "三月"),
    APRIL("1", "四月"),
    MAY("1", "五月"),
    JUNE("1", "六月"),
    JULY("1", "七月"),
    AUGUST("1", "八月"),
    SEPTEMBER("1", "九月"),
    OCTOMBER("1", "十月"),
    NOVEMBER("1", "十一月"),
    DECEMBER("1", "十二月"),

    ;
    private String code;
    private String name;

    /**
     * 类型转换器
     */
    public static class Converter extends AbstractEnumConverter<MonthEnum, String> {
        public Converter() {
            super(MonthEnum.class);
        }
    }


    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    @Nullable
    public static MonthEnum resolve(String name) {
        for(MonthEnum degreeEnum: MonthEnum.values()) {
            if(name.equals(degreeEnum.getName())){
                return degreeEnum;
            }
        }
        return null;
    }

    private static Random r = new Random();

    public static MonthEnum random() {
        return MonthEnum.values()[r.nextInt(3)];
    }
}
